<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/6/28 0028
  Time: 15:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>编辑收货地址</title>
    <script>
        $(function () {
//            $("#provinceCode").children("option").remove();
//            $("#cityCode").children("option").remove();
//            $("#districtCode").children("option").remove();
            $("#provinceCode").html('<option value="">--请选择省--</option>');
            $("#cityCode").html('<option value="">--请选择市--</option>');
            $("#districtCode").html('<option value="">--请选择区--</option>');

            <!--$("#provinceCode").val("${currentAddress.provinceCode}");-->
            $.getJSON("${ctx}/ajax/get_area?parentCode=", function(json){
                if(json!=null&&json.length>0) {
                    for (var i in json) {
                        if(json[i].areaCode=='${currentAddress.provinceCode}'){
                            $("#provinceCode").append("<option value='" + json[i].areaCode + "' selected>" + json[i].areaName + "</option>");
                        }else $("#provinceCode").append("<option value='" + json[i].areaCode + "'>" + json[i].areaName + "</option>");
                    }
                }
            });

            $.getJSON("${ctx}/ajax/get_area?parentCode=${currentAddress.provinceCode}", function(json){
                if(json!=null&&json.length>0) {
                    for (var i in json) {
                        if(json[i].areaCode=='${currentAddress.cityCode}'){
                            $("#cityCode").append("<option value='" + json[i].areaCode + "' selected>" + json[i].areaName + "</option>");
                        }else $("#cityCode").append("<option value='" + json[i].areaCode + "'>" + json[i].areaName + "</option>");
                    }
                }
            });

            $.getJSON("${ctx}/ajax/get_area?parentCode=${currentAddress.provinceCode}", function(json){
                if(json!=null&&json.length>0) {
                    for (var i in json) {
                        if(json[i].areaCode=='${currentAddress.cityCode}'){
                            $("#cityCode").append("<option value='" + json[i].areaCode + "' selected>" + json[i].areaName + "</option>");
                        }else $("#cityCode").append("<option value='" + json[i].areaCode + "'>" + json[i].areaName + "</option>");
                    }
                }
            });
            $.getJSON("${ctx}/ajax/get_area?parentCode=${currentAddress.cityCode}", function(json){
                if(json!=null&&json.length>0) {
                    for (var i in json) {
                        if(json[i].areaCode=='${currentAddress.districtCode}'){
                            $("#districtCode").append("<option value='" + json[i].areaCode + "' selected>" + json[i].areaName + "</option>");
                        }else $("#districtCode").append("<option value='" + json[i].areaCode + "'>" + json[i].areaName + "</option>");
                    }
                }
            });
            <%--})--%>
            //一级分类发生变化时
            $("#provinceCode").change(function () {
                $("#cityCode").removeAttr("style");
                $("#districtCode").removeAttr("style");
                $("#cityCode").children("option").remove();
                $("#districtCode").children("option").remove();
                $("#cityCode").append("<option value=''>"+"--请选择市--"+"</option>");
                $("#districtCode").append("<option value=''>"+"--请选择区--"+"</option>");
                var provinceCode=$("#provinceCode").val();
                //将选择的分类名追加到<p>
                $("#p1").text("");
                if($("#provinceCode").val()!=0) {
                    $("#p1").append($("#provinceCode option:selected").text());

                    $.getJSON("${ctx}/ajax/get_area?parentCode="+provinceCode, function(json){
                        if(json!=null&&json.length>0) {
                            for (var i in json) {
                                $("#cityCode").append("<option value='" + json[i].areaCode + "'>" + json[i].areaName + "</option>");
                            }
                        }
                    });
                }
            })
            //二级分类发生变化时
            $("#cityCode").change(function () {
                $("#districtCode").removeAttr("style");
                $("#districtCode").children("option").remove();
                $("#districtCode").append("<option value=''>"+"--请选择区--"+"</option>");
                var cityCode=$("#cityCode").val();
                //将选择的分类名追加到<p>
                $("#p1").text("");
                if($("#cityCode").val()!=0) {
                    $("#p1").append($("#provinceCode option:selected").text());

                    $.getJSON("${ctx}/ajax/get_area?parentCode="+cityCode, function(json) {
                        if(json!=null&&json.length>0) {
                            for (var i in json) {
                                $("#districtCode").append("<option value='" + json[i].areaCode + "'>" + json[i].areaName + "</option>");
                            }
                        }
                    });
                }
            })
        })
    </script>
    <script language="javascript">
        function del_sure(id) {
            var gnl = confirm("确定要删除地址?");
            console.log(gnl)
            if (gnl) {
                $.get("${ctx}/delete/address?id=" + id, function () {
                    window.location.href = "${ctx}/address";
                })
            }
        }
    </script>
    <script>
        function numberForm() {
            document.childForm.submit();
        }
    </script>
</head>
<body>
<form:form modelAttribute="UserShippingAddressModel" method="post" class="text-form" name="childForm">
    <form:hidden path="addressId"></form:hidden>
    <article class="viewports">
        <ul class="list_item2 c3">
            <li class="odr2_b plr20">

                    <%--<input class="i_text" type="text" value="李白">--%>
                <form:input path="consigneeName" cssClass="i_text" placeholder="收货人姓名"></form:input>
                <form:errors path="consigneeName" cssClass="i_text"></form:errors>
            </li>
            <li class="odr2_b plr20">
                <form:input path="consigneePhone" cssClass="i_text" type="number" maxlength="11"
                            placeholder="手机号码"></form:input>
                <form:errors path="consigneePhone" cssClass="i_text"></form:errors>
                    <%--<input class="i_text" type="text" value="13800138000">--%>
            </li>
            <li class="odr2_b plr20">
                <form:input path="zipCode" cssClass="i_text" type="number" placeholder="邮政编码"></form:input>
                    <%--<input class="i_text" type="text" value="10000">--%>
            </li>
            <form:errors path="zipCode" cssClass="i_text"></form:errors>
            <li class="odr2_b plr20">
            <span class="c0">
                 <form:select path="provinceCode" class="s_text">
                     <form:option value="">--请选择省--</form:option>
                 </form:select>
            <form:select path="cityCode" class="s_text">
                <form:option value="">--请选择市--</form:option>

            </form:select>

            <form:select path="districtCode" class="s_text">
                <form:option value="">--请选择区--</form:option>
            </form:select>
                </span>
                <span class="r">
                <i class="ico-30 ico_arrow"></i>
                </span>
            </li>
            <form:errors path="cityCode" cssClass="t_msg"></form:errors>
            <form:errors path="districtCode" cssClass="t_msg"></form:errors>
            <form:errors path="provinceCode" cssClass="t_msg"></form:errors>
            <li class="odr2_b plr20">
                <form:textarea path="address" cssClass="i_textarea" placeholder="详细地址"></form:textarea>
                    <%--<textarea class="i_textarea">街道上北大门76号北亭公寓B座808</textarea>--%>
            </li>
            <form:errors path="address" cssClass="t_msg"></form:errors>
        </ul>
        <div class="c p20">
            <div><label class="fwb c0">
                    <%--<input type="checkbox" class="mr10">设为默认地址</label>--%>
                <c:choose>
                <c:when test="${currentAddress.isDefault==1}">
                <input class="mr10" id="isDefault" name="isDefault" type="checkbox" value="1" checked="true">默认
                </c:when>
                <c:when test="${currentAddress.isDefault==0}">
                <input class="mr10" id="isDefault" name="isDefault" type="checkbox" value="1">默认
                </c:when>
                </c:choose>
            </div>

            <div>注：每次下单使用该地址</div>
        </div>
    </article>

    <!--star 底下按钮-->
    <div class="buy_height"></div>
    <div class="p_fotbtn tac">
        <a class="b-ffaa3b cf ptb25" onclick="numberForm();">保存并使用</a>
        <a class="b-ef2d2d cf ptb25" onclick="javascript:del_sure('${currentAddress.addressId}')">删除收货地址</a>
    </div>
</form:form>
<!--end 底下按钮-->
</body>
</html>


<%--<body>--%>
<%--<article>--%>
<%--<form:form modelAttribute="UserShippingAddressModel" method="post"   class="text-form" name="childForm">--%>
<%--<section class="mt30 odr_b odr_t">--%>
<%--<h2 class="tit"><i></i>收货地址</h2>--%>
<%--<form:hidden  path="addressId" value="${currentAddress.addressId}"></form:hidden>--%>

<%--<form:errors path="districtCode" cssClass="t_msg"></form:errors>--%>
<%--<form:errors path="cityCode" cssClass="t_msg"></form:errors>--%>
<%--<form:errors path="provinceCode" cssClass="t_msg"></form:errors>--%>
<%--<ul>--%>
<%--<li class="odr" id="user-name-label">--%>
<%--<form:input path="consigneeName" cssClass="s_text" value="${currentAddress.consigneeName}" placeholder="收货姓名"  ></form:input>--%>
<%--<form:errors path="consigneeName" cssClass="t_msg"></form:errors>--%>
<%--</li>--%>
<%--<li class="odr" id="user-phone-label">--%>
<%--<form:input path="consigneePhone" cssClass="s_text" type="number" value="${currentAddress.consigneePhone}" maxlength="11"  placeholder="联系方式" ></form:input>--%>
<%--<form:errors path="consigneePhone" cssClass="t_msg"></form:errors></li>--%>
<%--<div class="list_item2 p25">--%>
<%--<ul class="odr r5">--%>
<%--<li class="odr_b">--%>
<%--<form:select path="provinceCode" class="s_text">--%>
<%--<form:option value="">--请选择省--</form:option>--%>
<%--</form:select>--%>
<%--</li>--%>
<%--<li class="odr_b">--%>
<%--<form:select path="cityCode" class="s_text">--%>
<%--<form:option value="">--请选择市--</form:option>--%>
<%--</form:select>--%>
<%--</li>--%>
<%--<li class="odr_b">--%>
<%--<form:select path="districtCode" class="s_text">--%>
<%--<form:option value="">--请选择区--</form:option>--%>
<%--</form:select>--%>
<%--</li>--%>

<%--</ul>--%>
<%--</div>--%>
<%--<li class="odr" id="user-address-label">--%>
<%--<form:input path="address" cssClass="s_text"  value="${currentAddress.address}" placeholder="详细地址" ></form:input>--%>
<%--<form:errors path="address" cssClass="t_msg"></form:errors></li>--%>
<%--<label class="checkbox">--%>
<%--<c:choose>--%>
<%--<c:when test="${currentAddress.isDefault==1}">--%>
<%--<input id="isDefault" name="isDefault" type="checkbox" value="1" checked="true" >默认--%>
<%--</c:when>--%>
<%--<c:when test="${currentAddress.isDefault==0}">--%>
<%--<input id="isDefault" name="isDefault" type="checkbox" value="1"  >默认--%>
<%--</c:when>--%>
<%--</c:choose>--%>

<%--</label>--%>
<%--</ul>--%>
<%--</section>--%>
<%--<div class="plr25 mt30 c"><input id="btn" class="news_btn r5 fs32" type="submit" value="保存并使用"></input></div>--%>
<%--&lt;%&ndash;<a class="btn btn-xs js-deleteClassify"   onclick="javascript:del_sure('${currentAddress.addressId}')">删除</a>&ndash;%&gt;--%>
<%--<div class="plr25 mt30 c">  <a  onclick="javascript:del_sure('${currentAddress.addressId}')" class="news_btn r5 fs32" data-delete-confirm>删除</a></div>--%>
<%--</form:form>--%>
<%--</article>--%>
<%--</body>--%>
<%--</html>--%>

